package com.kcsj.service.user;

import com.kcsj.dao.User.FileDao;
import com.kcsj.domain.File;
import com.kcsj.util.JdbcHelper;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.Collection;
/**
 * @author 胡庆阳
 * 29th Nov. 2020
 */

public class FileService {
    private final FileDao fileDao = FileDao.getInstance();
    private static final FileService fileService = new FileService();

    public FileService() {
    }

    public static FileService getInstance(){
        return fileService;
    }

    public Collection<File> findAll() throws SQLException {
        Connection conn = JdbcHelper.getConn();
        Collection<File> Files = fileDao.findAll(conn);
        JdbcHelper.close(conn);
        return Files;
    }


    public int addFile(File File) throws SQLException {
        Connection conn = JdbcHelper.getConn();
        Integer id = fileDao.add(File,conn);
        JdbcHelper.close(conn);
        return id;
    }
}
